<?php

namespace app\adminapi\controller\v1\setting;

use app\adminapi\controller\AuthController;
use app\model\setting\admin\SystemGroupAccess;
use app\model\setting\admin\SystemUser;
use app\Request;
use app\services\setting\SystemMenusService;
use think\facade\App;

class SystemMenus extends AuthController
{

    public function __construct(App $app, SystemMenusService $service)
    {
        parent::__construct($app);
        $this->services = $service;
    }

    public function index()
    {
        $where = $this->request->getMore([
            ['page', 1],
            ['pageSize', 20],
        ]);
        $where['accessToken'] = $this -> request -> header('accessToken');
        return app('json')->successful($this->services->getList($where));


    }

    public function getMenusList()
    {
        $where = $this->request->getMore([
            ['page', 1],
            ['pageSize', 20],
        ]);
        return app('json')->successful($this->services->getMenusList($where));
    }


    /**
     * 添加菜单数据
     * @return mixed
     */
    public function create()
    {
        $where = $this->request->postMore([
            ['pid', 0],
            ['pids', ''],
            ['name', ''],
            ['title', ''],
            ['affix', 0],
            ['hidden', 0],
            ['icon', ''],
            ['badge', ''],
            ['weight', ''],
            ['status', ''],
            ['menu', ''],
            ['condition', ''],
            ['front', ''],
            ['routePath', ''],
            ['componentsPath', ''],
            ['noKeepAlive', ''],
            ['breadcrumb', ''],
            ['remixIcon', ''],
            ['permission', '']
        ]);
        $where['website_id'] = $this -> request -> header('website');

        return app()->make('json')->successful($this->services->create($where));
    }


    /**
     * 修改菜单数据
     * @return mixed
     */
    public function update()
    {
        $where = $this->request->postMore([
            ['pid', 0],
            ['id', 0],
            ['pids', ''],
            ['name', ''],
            ['title', ''],
            ['affix', 0],
            ['hidden', 0],
            ['icon', ''],
            ['badge', ''],
            ['weight', ''],
            ['status', ''],
            ['menu', ''],
            ['condition', ''],
            ['front', ''],
            ['routePath', 0],
            ['componentsPath', 0],
            ['noKeepAlive', ''],
            ['breadcrumb', ''],
            ['remixIcon', ''],
            ['permission', '']
        ]);
        $where['website_id'] = $this -> request -> header('website');
        return app()->make('json')->successful($this->services->update($where));
    }

    public function delete()
    {
        $where = $this->request->getMore([
            ['id', ''],
        ]);
        return app('json')->successful($this->services->delete($where));

    }

    public function searchTitle()
    {
        $where = $this->request->getMore([
            ['title', ''],
        ]);
        return app('json')->successful($this->services->searchTitle($where));

    }


    public function searchPidAndNotMenu()
    {
        $where = $this->request->getMore([
            ['id', ''],
        ]);
        return app('json')->successful($this->services->searchPidAndNotMenu($where));

    }


}